﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using SsTool.Metadata.Windows;
using SmartSpace.Core;
using SmartSpace.Core.Metadata;
using SmartSpace.Data;

namespace SsTool.Metadata
{
    /// <summary>
    /// Interaction logic for PropertyTypeMetadataPage.xaml
    /// </summary>
    public partial class PropertyTypeMetadataPage : Page
    {
        public PropertyTypeMetadataPage()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(PropertyTypeMetadataPage_Loaded);
        }

        void PropertyTypeMetadataPage_Loaded(object sender, RoutedEventArgs e)
        {
            LoadDatas();
        }

        private void LoadDatas()
        {
            IDataService service = App.Get<IDataService>();
            _ctlGrid.ItemsSource = service.FindTypes(0, 999);
        }

        private void _ctlBtnCreate_Click(object sender, RoutedEventArgs e)
        {
            PropertyTypeMetadataWindow window = new PropertyTypeMetadataWindow();
            if (window.ShowDialog() == true)
            {
                LoadDatas();
            }
        }

        private void _ctlBtnCreateParser_Click(object sender, RoutedEventArgs e)
        {
            TypeMetadata selectType = _ctlGrid.SelectedItem as TypeMetadata;
            if (selectType != null)
            {
                if (_ctlGridParser.ItemsSource != null)
                {
                    return;
                }
            }
        }

        private void _ctlGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            TypeMetadata selectType = _ctlGrid.SelectedItem as TypeMetadata;
            if (selectType != null)
            {
            }
        }

        private void _ctlBtnUpdate_Click(object sender, RoutedEventArgs e)
        {
            TypeMetadata selectType = _ctlGrid.SelectedItem as TypeMetadata;
            if (selectType != null)
            {
                PropertyTypeMetadataWindow window = new PropertyTypeMetadataWindow(selectType);
                if (window.ShowDialog() == true)
                {
                    LoadDatas();
                }
            }
        }
    }
}
